﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MC.RideEvent.Mvc.Models.Repository;

namespace MC.RideEvent.Mvc.Controllers
{
    public class VehiculeApiController : Controller
    {
        private IVehiculeRepository _vehiculeRepo;
        private IVehiculeBrandRepository _BrandRepo;
        private IVehiculeModelRepository _ModelRepo;

        public VehiculeApiController(IVehiculeRepository vehiculeRepo, IVehiculeBrandRepository brandRepo, IVehiculeModelRepository modelRepo)
        {
            _vehiculeRepo = vehiculeRepo;
            _BrandRepo = brandRepo;
            _ModelRepo = modelRepo;
        }

        public JsonResult VehiculesMember(int memberId)
        {
            var list = _vehiculeRepo.GetVehiculesMember(memberId);

            return Json(list, JsonRequestBehavior.AllowGet);
        }

        public JsonResult VechiculeMemberPlaces(int vehiculeIdSelected)
        {
            var vehiculeSelected = _vehiculeRepo.GetVehiculeById(vehiculeIdSelected);
            var nbPlaces = vehiculeSelected.NumberPlaces;

            var listDatas = new List<object>();
            for (int i = 1; i <= nbPlaces; i++)
            {
                listDatas.Add(new { text = i, value = i });
            }

            return Json(listDatas, JsonRequestBehavior.AllowGet);
        }

        public JsonResult Brands()
        {
            var list = _BrandRepo.ListBrand();

            return Json(list, JsonRequestBehavior.AllowGet);
        }

        public JsonResult Models(int brandId)
        {
            var list = _ModelRepo.ListModelByBrandId(brandId);

            return Json(list, JsonRequestBehavior.AllowGet);
        }
    }
}
